package com.umeox.watch.moto.chat.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.umeox.moto.common.log.Logger
import com.umeox.watch.moto.chat.BuildConfig
import com.umeox.watch.moto.chat.db.AppDatabase
import com.umeox.watch.moto.chat.db.ContactInfo
import com.umeox.watch.moto.chat.db.DBUtils
import com.umeox.watch.moto.chat.db.MessageDelegate
import com.umeox.watch.moto.dataservice.constants.Constants

/**
 * Created by Rambo 2021/8/17
 * Describe:
 */
class ChatReceiver : BroadcastReceiver() {


    override fun onReceive(context: Context?, intent: Intent?) {
        if (BuildConfig.DEBUG) {
            Logger.i("[ChatReceiver] onReceive - " + intent?.action)
        }

        if (Constants.ACTION_NEW_CHAT_MESSAGE == intent?.action) {
            val chaMsgList = intent.getByteArrayExtra(Constants.EXTRA_CHAT_MSG)
            if (chaMsgList == null) {
                Logger.w("消息列表为空")
                return
            }
            MessageDelegate.getManager().handleIncomingMessage(chaMsgList)
        }
    }

}